import AbTestMgr from "./AbTestMgr";
import EventMgr from "./EventMgr";
import GameEventType from "./GameEventType";
import EngineUtil from "./EngineUtil";
import BasePageCtrl from "./BasePageCtrl";
import BigToastPage from "./BigToastPage";

const { ccclass, property } = cc._decorator;

@ccclass
export default class BigToastPageCtrl extends BasePageCtrl {

    onLoad() {
        this.onUILoad();
        this.addButtonListen();
        super.onLoad();
    }

    onUILoad() {
        this.ui = this.node.addComponent(BigToastPage);
    }

    addButtonListen() {}

    _init(e?) {
        var t = this;
        if (e) {
            var a = e.reward_cash,
                o = e.reward_fund;
            if (AbTestMgr.isOptimizeTravelFundFlag()) {
                this.ui.redPaper.x = 135;
                this.ui.fund.x = -132;
                this.ui.moneyLabel.getComponent(cc.Label).string = "+" + EngineUtil.getCashBalance(a) + "";
                this.ui.fundLabel.getComponent(cc.Label).string = "+" + EngineUtil.getCashBalance(o) + "";
            } else {
                this.ui.redPaper.x = -132;
                this.ui.fund.x = 135;
                this.ui.moneyLabel.getComponent(cc.Label).string = "+" + EngineUtil.getCashBalance(a) + "";
                this.ui.fundLabel.getComponent(cc.Label).string = "+ " + EngineUtil.getCashBalance(o) + " ";
            }
            this.scheduleOnce(() => {
                EventMgr.trigger(GameEventType.FLY_REWARD_CASH, { pos: t.ui.redPaper.getPosition() });
                EventMgr.trigger(GameEventType.FLY_REWARD_FUND, { pos: t.ui.fund.getPosition() });
            }, 0.8);
            this.scheduleOnce(() => {
                t.hide();
            }, 1.1);
        }
    }

    clickClose() {
        this.hide();
    }
}
